

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/boshi.jpeg">
  <link rel="icon" type="image/png" href="/img/boshi.jpeg">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="">
  <meta name="author" content="wangpf">
  <meta name="keywords" content="">
  <title>Redux 学习总结 - wpf的博客</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/foundation.min.css" />
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_6peoq002giu.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_pjno9b9zyxs.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.1.1"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>Wangpf's blog</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" href="javascript:">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner intro-2" id="background" parallax=true
         style="background: url('/img/article.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container page-header text-center fade-in-up">
            <span class="h2" id="subtitle">
              
            </span>

            
              
  <div class="mt-3 post-meta">
    <i class="iconfont icon-date-fill" aria-hidden="true"></i>
    <time datetime="2021-01-31 09:52" pubdate>
      2021年1月31日 上午
    </time>
  </div>


<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      1.5k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      20
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto" id="post">
            <!-- SEO header -->
            <h1 style="display: none">Redux 学习总结</h1>
            
            <div class="markdown-body" id="post-body">
              <h2 id="redux-是什么"><a href="#redux-是什么" class="headerlink" title="redux 是什么"></a>redux 是什么</h2><ol>
<li>rduex是一个专门用于做状态管理的JS库（注意:不是React插件库）</li>
<li>它可以在任何框架里使用，也可以在原生JS中使用，但基本与react搭配使用</li>
<li>作用:集中式管理 多个组件共享的状态</li>
</ol>
<h2 id="redux原理"><a href="#redux原理" class="headerlink" title="redux原理"></a>redux原理</h2><p><img src="https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/894ca0cbc1f349af965aaa07bb97386b~tplv-k3u1fbpfcp-watermark.image" srcset="/img/loading.gif" alt="redux原理图"></p>
<p>看图很抽象，需要用一个生活中的例子来形象表达出来，估计会理解的更深。</p>
<p>比如： 我饿了，去餐馆吃饭，我给服务员说我要一份蛋炒饭，然后服务员把菜单传给餐馆老板，老板通知厨师要求做一份蛋炒饭，厨师做完蛋炒饭后再交给老板，然后我自己去取餐。</p>
<p>现在，我就是：React Components ， 服务员就是 Action Creators ， 餐馆老板就是: Store, 后厨就是：Reducers 。</p>
<p>瞧，redux就是这样一个工作流程，是不是感觉很生活？</p>
<p>即：action 定义状态，dispatch派发状态，store执行，reducers执行，reducers返回一个新的状态，然后getstate更新视图</p>
<h2 id="redux-三个核心概念"><a href="#redux-三个核心概念" class="headerlink" title="redux 三个核心概念"></a>redux 三个核心概念</h2><h3 id="1-action"><a href="#1-action" class="headerlink" title="1. action"></a>1. action</h3><ol>
<li>动作的对象</li>
<li>包含 俩个属性<ul>
<li>type: 标识属性，值为字符串，唯一，必要属性</li>
<li>data: 数据属性，值类型任意，可选属性</li>
</ul>
</li>
<li>例子： {type:”ADD_USER”,data:{name:”Wangpf”,age:”18”}}</li>
</ol>
<h3 id="2-reducer"><a href="#2-reducer" class="headerlink" title="2. reducer"></a>2. reducer</h3><ol>
<li>用于初始化状态，加工状态。</li>
<li>加工时，根据 旧的 state 和 action ，产生新的 state 的<strong>纯函数</strong></li>
</ol>
<h3 id="3-store"><a href="#3-store" class="headerlink" title="3. store"></a>3. store</h3><p>将 state 、 action 、 reducer 联系在一起的对象</p>
<h2 id="先通过一个小案例来体现简单版的redux"><a href="#先通过一个小案例来体现简单版的redux" class="headerlink" title="先通过一个小案例来体现简单版的redux"></a>先通过一个小案例来体现简单版的redux</h2><p>redux使用步骤</p>
<ol>
<li><p><strong>创建 reducer.js</strong></p>
<ul>
<li>renducer 的本质是一个函数，接收 preState,action， 返回加工后的状态</li>
<li>renducer 有俩个作用： 初始化状态，加工状态</li>
<li>注意：renducer 被第一次调用时，是store自动触发的<ul>
<li>传递的 preState是 undefined</li>
<li>传递的 action 是：{type:”@@REDUX/INIT_d.5.f.4”} 类似于这种形式的</li>
</ul>
</li>
<li>通过<strong>dispatc（aciton）</strong>，把state（{type,data}）放入reducer函数中加工，并返回新的state。</li>
</ul>
</li>
<li><p><strong>创建 store.js</strong></p>
<ul>
<li>引入 redux 中的 <code>createStore</code>方法，创建一个store</li>
<li><code>createStore</code>调用时要传入一个为其服务的 reducer</li>
<li>即在此文件中 使用 <code>createStore</code> API</li>
</ul>
</li>
<li><p><strong>在组件中引入 store</strong></p>
<ul>
<li>使用 <strong>getState，dispatch，subscribe</strong>等API来实现状态更新。</li>
</ul>
</li>
</ol>
<p>小试牛刀，按照上面步骤，相应代码如下：</p>
<div class="hljs"><pre><code class="hljs jsx"><span class="hljs-comment">// count_reducer JS文件</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">countReducer</span>(<span class="hljs-params">preState =<span class="hljs-number">0</span>, action</span>) </span>&#123;
  <span class="hljs-keyword">const</span> &#123; type, data &#125; = action
  <span class="hljs-keyword">const</span> typeMap = &#123;
    <span class="hljs-string">&quot;increment&quot;</span>: preState + data,
    <span class="hljs-string">&quot;decrement&quot;</span>: preState - data
  &#125;
  <span class="hljs-keyword">if</span> (type <span class="hljs-keyword">in</span> typeMap) &#123;
    <span class="hljs-keyword">return</span> typeMap[type]
  &#125; <span class="hljs-keyword">else</span> &#123;
    <span class="hljs-keyword">return</span> preState
  &#125;
&#125;
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> countReducer</code></pre></div>

<div class="hljs"><pre><code class="hljs jsx"><span class="hljs-comment">// store js文件</span>
<span class="hljs-keyword">import</span> &#123; createStore &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;redux&#x27;</span>

<span class="hljs-keyword">import</span> countReducer <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;./count_reducer&#x27;</span>

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> createStore(countReducer)</code></pre></div>

<div class="hljs"><pre><code class="hljs jsx"><span class="hljs-comment">// 组件 方法代码</span>

<span class="hljs-comment">// render 方法中的  &lt;h2&gt;当前求和为：&#123;store.getState()&#125;&lt;/h2&gt;</span>

  componentDidMount() &#123;
    store.subscribe(<span class="hljs-function">() =&gt;</span> &#123;
      <span class="hljs-built_in">this</span>.setState(&#123;&#125;)
    &#125;)
  &#125;

  <span class="hljs-comment">// 加法</span>
  increment = <span class="hljs-function">() =&gt;</span> &#123;
    <span class="hljs-keyword">const</span> &#123; value &#125; = <span class="hljs-built_in">this</span>.currentNum
    store.dispatch(&#123; <span class="hljs-attr">type</span>: <span class="hljs-string">&quot;increment&quot;</span>, <span class="hljs-attr">data</span>: value * <span class="hljs-number">1</span> &#125;)
  &#125;

  <span class="hljs-comment">// 减法</span>
  decrement = <span class="hljs-function">() =&gt;</span> &#123;
    <span class="hljs-keyword">const</span> &#123; value &#125; = <span class="hljs-built_in">this</span>.currentNum
    store.dispatch(&#123; <span class="hljs-attr">type</span>: <span class="hljs-string">&quot;decrement&quot;</span>, <span class="hljs-attr">data</span>: value * <span class="hljs-number">1</span> &#125;)
  &#125;
</code></pre></div>

<p>目前我们还没有用上 action 这个概念， 所以把代码优化一下：</p>
<p>优化步骤：</p>
<ol>
<li>创建 action.js<ul>
<li>用来记录用户发生的动作</li>
<li>专门用于创建action对象</li>
</ul>
</li>
<li>创建 constant.js<ul>
<li>使用变量控制action中的type，统一管理并防止单词出错</li>
</ul>
</li>
</ol>
<p>代码如下(我放在一起了)：</p>
<div class="hljs"><pre><code class="hljs js"><span class="hljs-comment">// constant.js</span>
<span class="hljs-comment">// 该模块是用于 定义action对象中的type类型的常量值，目的只有一个：便于管理的同时防止单词写错</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> INCREMENT = <span class="hljs-string">&#x27;increment&#x27;</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> DECREMENT = <span class="hljs-string">&#x27;decrement&#x27;</span>


<span class="hljs-comment">// action.js</span>
<span class="hljs-keyword">import</span> &#123; INCREMENT,DECREMENT&#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;./constant&#x27;</span>

<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> createIncrementAction = <span class="hljs-function"><span class="hljs-params">data</span> =&gt;</span> (&#123; <span class="hljs-attr">type</span>: INCREMENT, data&#125;)
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> createDecrementAction = <span class="hljs-function"><span class="hljs-params">data</span> =&gt;</span> (&#123; <span class="hljs-attr">type</span>: DECREMENT, data&#125;)


<span class="hljs-comment">// reducer.js 代码部分优化</span>
<span class="hljs-comment">// 把原来的字符串改为变量名</span>
 <span class="hljs-keyword">const</span> typeMap = &#123;
    [INCREMENT]: preState + data,
    [DECREMENT]: preState - data
  &#125;

<span class="hljs-comment">// 组件  实现方法代码优化</span>
  increment = <span class="hljs-function">() =&gt;</span> &#123;
    <span class="hljs-keyword">const</span> &#123; value &#125; = <span class="hljs-built_in">this</span>.currentNum
    store.dispatch(createIncrementAction(value * <span class="hljs-number">1</span>))
  &#125;
  decrement = <span class="hljs-function">() =&gt;</span> &#123;
    <span class="hljs-keyword">const</span> &#123; value &#125; = <span class="hljs-built_in">this</span>.currentNum
    store.dispatch(createDecrementAction(value * <span class="hljs-number">1</span>))
  &#125;
</code></pre></div>


<p>以上就 过了一遍如何使用<strong>redux</strong>的一个简单流程。</p>
<h2 id="异步-action"><a href="#异步-action" class="headerlink" title="异步 action"></a>异步 action</h2><p><strong>使用前提：</strong> 如果我们不想把 延迟的动作交给组件自身（也就是异步操作不想在组件内上实现），而想交给action来处理。</p>
<p><strong>什么时候需要异步action：</strong> 想要对状态进行操作，但是具体的数据需要靠异步任务返回。</p>
<p>具体步骤：</p>
<ol>
<li>npm install redux-thunk， 并在store中配置它<div class="hljs"><pre><code class="hljs jsx"><span class="hljs-keyword">import</span> &#123; createStore,applyMiddleware &#125; <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;redux&#x27;</span>
<span class="hljs-comment">// 用于支持异步action</span>
<span class="hljs-keyword">import</span> thunk <span class="hljs-keyword">from</span> <span class="hljs-string">&#x27;redux-thunk&#x27;</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> createStore(countReducer,applyMiddleware(thunk))</code></pre></div></li>
<li>创建action的函数不再返回一般对象，而是一个函数，因为函数可以写异步任务。</li>
<li>异步任务有结果后，发布一个同步的action去真正操作数据</li>
</ol>
<p>案例代码如下：</p>
<div class="hljs"><pre><code class="hljs jsx"><span class="hljs-comment">// action.js</span>
<span class="hljs-comment">// 处理 异步    它必须返回的是一个 函数</span>
<span class="hljs-keyword">export</span> <span class="hljs-keyword">const</span> createIncrementAsyncAction = <span class="hljs-function">(<span class="hljs-params">data,time</span>) =&gt;</span> &#123;
  <span class="hljs-keyword">return</span> <span class="hljs-function">(<span class="hljs-params">dispatch</span>) =&gt;</span> &#123;
    <span class="hljs-built_in">setTimeout</span>(<span class="hljs-function">() =&gt;</span> &#123;
      dispatch(&#123; <span class="hljs-attr">type</span>: DECREMENT, data &#125;)
     &#125;,time)
   &#125;
&#125;

<span class="hljs-comment">// 组件内的</span>
  incrementAsync = <span class="hljs-function">() =&gt;</span> &#123;
    <span class="hljs-keyword">const</span> &#123; value &#125; = <span class="hljs-built_in">this</span>.currentNum
    store.dispatch(createIncrementAsyncAction(value * <span class="hljs-number">1</span>, <span class="hljs-number">500</span>))
  &#125;</code></pre></div>


<p><strong>总结:</strong> 其实我们完全可以自己等待异步任务的结果后再去发布同步action，所以感觉这个 异步action不太重要，了解即可。</p>
<h2 id="react-redux"><a href="#react-redux" class="headerlink" title="react-redux"></a>react-redux</h2><h3 id="需要明确俩个概念："><a href="#需要明确俩个概念：" class="headerlink" title="需要明确俩个概念："></a>需要明确俩个概念：</h3><ol>
<li><strong>UI组件：</strong> 不能使用任何 render 的api，只负责页面的呈现，交互等，状态完全由外部控制。</li>
<li><strong>容器组件：</strong>  负责和redux通信，将结果交给UI组件。</li>
</ol>
<h3 id="需要明确俩个核心："><a href="#需要明确俩个核心：" class="headerlink" title="需要明确俩个核心："></a>需要明确俩个核心：</h3><p><strong>Provider 和 connect</strong></p>
<h4 id="Provider"><a href="#Provider" class="headerlink" title="Provider"></a>Provider</h4><p><strong>Provider</strong> 的目的是让所有组件都能够访问到redux中的数据。</p>
<div class="hljs"><pre><code class="hljs jsx">ReactDOM.render(
  &lt;Provider store=&#123;store&#125;&gt;
    &lt;App /&gt;
  &lt;/Provider&gt;,
  <span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">&quot;root&quot;</span>)
)</code></pre></div>
<h4 id="connect"><a href="#connect" class="headerlink" title="connect"></a>connect</h4><p>首先，它的使用是这样子的：</p>
<div class="hljs"><pre><code class="hljs js">connect(mapStateToProps, mapDispatchToProps)(component)</code></pre></div>

<p><strong>mapStateToProps:</strong></p>
<ul>
<li>中文意思: 把state映射到props中。</li>
<li>映射状态，返回值是一个对象</li>
</ul>
<div class="hljs"><pre><code class="hljs jsx"><span class="hljs-comment">// 容器组件：</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mapStateToProps</span>(<span class="hljs-params">state</span>) </span>&#123;
  <span class="hljs-comment">// 比如 state = &#123; a:123 &#125;</span>
  <span class="hljs-keyword">return</span> &#123; <span class="hljs-attr">foo</span>: state.a &#125;
&#125;

<span class="hljs-comment">//  UI组件：</span>
render()&#123;
 <span class="hljs-keyword">return</span> (
  &lt;div&gt;&#123; <span class="hljs-built_in">this</span>.props.foo &#125;&lt;<span class="hljs-regexp">/div&gt;  /</span><span class="hljs-regexp">/ 123</span>
<span class="hljs-regexp"> )</span>
<span class="hljs-regexp">&#125;</span></code></pre></div>

<p><strong>mapDispatchToProps：</strong></p>
<ul>
<li>中文意思:把各种dispatch也映射到props中的供你使用</li>
<li>映射操作状态的方法，返回值是一个对象</li>
</ul>
<div class="hljs"><pre><code class="hljs jsx"><span class="hljs-comment">// 容器组件：</span>
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">mapDispatchToProps</span>(<span class="hljs-params">dispatch</span>) </span>&#123;
  <span class="hljs-keyword">return</span> &#123;
     add: <span class="hljs-function"><span class="hljs-params">number</span> =&gt;</span> dispatch(&#123;<span class="hljs-attr">type</span>:<span class="hljs-string">&quot;increment&quot;</span>&#125;,number),
  &#125;
&#125;

<span class="hljs-comment">//  UI组件：</span>
&lt;button onClick=&#123;<span class="hljs-built_in">this</span>.props.add(<span class="hljs-number">1</span>)&#125;&gt; + &lt;/button&gt;</code></pre></div>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                <div class="post-meta mr-3">
                  <i class="iconfont icon-category"></i>
                  
                  <a class="hover-with-bg" href="/categories/React/">React</a>
                  
                  <a class="hover-with-bg" href="/categories/React/Redux/">Redux</a>
                  
                </div>
                
                
                <div class="post-meta">
                  <i class="iconfont icon-tags"></i>
                  
                  <a class="hover-with-bg" href="/tags/React/">React</a>
                  
                  <a class="hover-with-bg" href="/tags/Redux/">Redux</a>
                  
                </div>
                
              </div>
              
              
              <div class="post-prevnext row">
                <article class="post-prev col-6">
                  
                  
                  <a href="/2021/02/02/50-React%20Hooks/">
                    <i class="iconfont icon-arrowleft"></i>
                    <span class="hidden-mobile">React Hooks 学习总结</span>
                    <span class="visible-mobile">上一篇</span>
                  </a>
                  
                </article>
                <article class="post-next col-6">
                  
                  
                  <a href="/2021/01/26/48-%E8%99%9A%E6%8B%9FDOM/">
                    <span class="hidden-mobile">虚拟DOM和diff算法以及关于key的问题（学习总结）</span>
                    <span class="visible-mobile">下一篇</span>
                    <i class="iconfont icon-arrowright"></i>
                  </a>
                  
                </article>
              </div>
              
            </div>

            
            <!-- Comments -->
            <article class="comments" id="comments">
              
              
  <div id="vcomments"></div>
  <script type="text/javascript">
    function loadValine() {
      addScript('https://cdn.staticfile.org/valine/1.4.14/Valine.min.js', function () {
        new Valine({
          el: "#vcomments",
          app_id: "hjxsDRXYScicliqD8I8JqoTu-gzGzoHsz",
          app_key: "qUcAEReEqeEVp5wwXJ41uCCp",
          placeholder: "说点什么",
          path: window.location.pathname,
          avatar: "retro",
          meta: ["nick","mail","link"],
          pageSize: "10",
          lang: "zh-CN",
          highlight: true,
          recordIP: false,
          serverURLs: "",
        });
      });
    }
    waitElementVisible('vcomments', loadValine);
  </script>
  <noscript>Please enable JavaScript to view the <a target="_blank" href="https://valine.js.org" rel="nofollow noopener noopener">comments
      powered by Valine.</a></noscript>


            </article>
            
          </article>
        </div>
      </div>
    </div>
    
    <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
      <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

    </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  

  <footer class="mt-5">
  <div class="text-center py-3">
    <div>
      <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a>
      <i class="iconfont icon-love"></i>
      <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener">
        <span>Fluid</span></a>
    </div>
    
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


    

    
  </div>
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    
      <script  src="/js/lazyload.js" ></script>
    
  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: '#post-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "Redux 学习总结&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "always",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>







  
  
    <script>
      !function (e, t, a) {
        function r() {
          for (var e = 0; e < s.length; e++) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[e].y--, s[e].scale += .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:" + s[e].x + "px;top:" + s[e].y + "px;opacity:" + s[e].alpha + ";transform:scale(" + s[e].scale + "," + s[e].scale + ") rotate(45deg);background:" + s[e].color + ";z-index:99999");
          requestAnimationFrame(r)
        }

        function n() {
          var t = "function" == typeof e.onclick && e.onclick;
          e.onclick = function (e) {
            t && t(), o(e)
          }
        }

        function o(e) {
          var a = t.createElement("div");
          a.className = "heart", s.push({
            el: a,
            x: e.clientX - 5,
            y: e.clientY - 5,
            scale: 1,
            alpha: 1,
            color: c()
          }), t.body.appendChild(a)
        }

        function i(e) {
          var a = t.createElement("style");
          a.type = "text/css";
          try {
            a.appendChild(t.createTextNode(e))
          } catch (t) {
            a.styleSheet.cssText = e
          }
          t.getElementsByTagName("head")[0].appendChild(a)
        }

        function c() {
          return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"
        }

        var s = [];
        e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) {
          setTimeout(e, 1e3 / 60)
        }, i(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"), n(), r()
      }(window, document);
    </script>
  











  

  

  

  

  

  





</body>
</html>
